#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5,M=4e3+50;
long long n,ans,bj1,siz[N],fa[N];
map<int,int>bj[N];
vector<int>q[N];
struct node{
	int l,r,z;
}a[N];
queue<node>qwq;
void dfs(int i)
{
	siz[i]=1;
	for(int j=0;j<q[i].size();++j)
	{
		if(q[i][j]==fa[i]) continue;
		fa[q[i][j]]=i;
		dfs(q[i][j]);
		siz[i]+=siz[q[i][j]];
	}
	for(int j=0;j<q[i].size();++j)
	{
		if(q[i][j]==fa[i]) continue;
		fa[q[i][j]]=i;
		ans+=siz[q[i][j]]*(n-siz[q[i][j]]);
	}
}
int main()
{
	freopen("game.in","r",stdin);
	freopen("game.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i].l>>a[i].r,a[i].l+=10,a[i].r+=10;
	if(n<=4e3)
	{
		for(int i=1;i<=n;++i)
		{
			qwq.push((node){a[i].l,a[i].r,0});
			for(int j=1;j<=n;++j)
				bj[a[j].l][a[j].r]=1e9;
			bj[a[i].l][a[i].r]=0;
			while(!qwq.empty())
			{
				int nowl=qwq.front().l,nowr=qwq.front().r,nowz=qwq.front().z;
				ans+=nowz; 
				qwq.pop();
				if(bj[nowl+1][nowr]>nowz+1)
				{
					bj[nowl+1][nowr]=nowz+1;
					qwq.push((node){nowl+1,nowr,nowz+1});
				}
				if(bj[nowl-1][nowr]>nowz+1)
				{
					bj[nowl-1][nowr]=nowz+1;
					qwq.push((node){nowl-1,nowr,nowz+1});
				}
				if(bj[nowl][nowr+1]>nowz+1)
				{
					bj[nowl][nowr+1]=nowz+1;
					qwq.push((node){nowl,nowr+1,nowz+1});
				}
				if(bj[nowl][nowr-1]>nowz+1)
				{
					bj[nowl][nowr-1]=nowz+1;
					qwq.push((node){nowl,nowr-1,nowz+1});
				}
			}
		}
		cout<<ans/2<<'\n';
		return 0;
	}
	bj1=0;
	int mnx=1e9,mny=1e9,mxx=0,mxy=0;
	for(int i=1;i<=n;++i)
		mnx=min(mnx,a[i].l),mxx=max(mxx,a[i].l),mny=min(mny,a[i].r),mxy=max(mxy,a[i].r);
	if((mxx-mnx+1)*(mxy-mny+1)==n)
	{
		for(int i=1;i<=n;++i)
		{	
			ans+=((mxx-a[i].l)*(mxx-a[i].l+1)/2)*(mxy-mny+1)+((a[i].l-mnx)*(a[i].l-mnx+1)/2)*(mxy-mny+1)+(((mxy-a[i].r)*(mxy-a[i].r+1))/2)*(mxx-mnx+1)+(((a[i].r-mny)*(a[i].r-mny+1)/2)*(mxx-mnx+1));
		}
			cout<<ans/2<<'\n';
		return 0;
	}
	else{
		for(int i=1;i<=n;++i)
			bj[a[i].l][a[i].r]=i;
		for(int i=1;i<=n;++i)
		{
			if(bj[a[i].l+1][a[i].r])
				q[i].push_back(bj[a[i].l+1][a[i].r]);
			if(bj[a[i].l][a[i].r+1])
				q[i].push_back(bj[a[i].l][a[i].r+1]);
			if(bj[a[i].l-1][a[i].r])
				q[i].push_back(bj[a[i].l-1][a[i].r]);
			if(bj[a[i].l][a[i].r-1])
				q[i].push_back(bj[a[i].l][a[i].r-1]);
		}
		dfs(1);
		cout<<ans<<'\n';
		return 0;
	}
	return 0; 
 } 
